package pers.yurwisher.rubick.oauth2.exception;

import com.alibaba.fastjson.JSON;
import org.springframework.security.oauth2.common.exceptions.OAuth2Exception;
import pers.yurwisher.rubick.common.enums.tip.OAuth2CustomTipEnum;
import pers.yurwisher.rubick.common.wrapper.CustomTip;
import pers.yurwisher.rubick.common.wrapper.R;

/**
 *
 * @author yq
 * @date 2021/04/15 21:44
 * @since V1.0.0
 * @description 自定义oauth异常
 */
public class OAuth2CustomException extends OAuth2Exception {

    private static final long serialVersionUID = -1316676650588228823L;

    protected CustomTip tip;

    public OAuth2CustomException(CustomTip customTip) {
        super(customTip.getMsg());
        this.tip = customTip;
    }

    public OAuth2CustomException(CustomTip customTip, Object... args) {
        this(CustomTip.of(customTip.getCode(), String.format(customTip.getMsg(), args)));
    }

    public OAuth2CustomException(OAuth2CustomTipEnum customTipEnum) {
        this(customTipEnum.tip());
    }

    public OAuth2CustomException(OAuth2CustomTipEnum customTipEnum, Object... args) {
        this(customTipEnum.tip(), args);
    }

    @Override
    public String toString() {
        return JSON.toJSONString(R.fail(tip));
    }
}
